<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">病例编号</label>
        <el-input v-model="query.id" clearable placeholder="病例编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">患者编号</label>
        <el-input v-model="query.patientId" clearable placeholder="患者编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">医生编号</label>
        <el-input v-model="query.doctorId" clearable placeholder="医生编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">记录类型</label>
        <el-input v-model="query.recordType" clearable placeholder="记录类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">状态  dict=record_stat</label>
        <el-input v-model="query.stat" clearable placeholder="状态  dict=record_stat" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">诊所ID</label>
        <el-input v-model="query.clinicId" clearable placeholder="诊所ID" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">STL标识：0 寄送牙模，1 上传STL文件</label>
        <el-input v-model="query.stlFlag" clearable placeholder="STL标识：0 寄送牙模，1 上传STL文件" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">cbct标识：0 上传X光照 ，1 上传CBCT文件 </label>
        <el-input v-model="query.cbctFlag" clearable placeholder="cbct标识：0 上传X光照 ，1 上传CBCT文件 " style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">是否需要报告 0 不需要 1 需要</label>
        <el-input v-model="query.reportFlag" clearable placeholder="是否需要报告 0 不需要 1 需要" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">牙模的快递单号</label>
        <el-input v-model="query.expressNo" clearable placeholder="牙模的快递单号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">套餐ID</label>
        <el-input v-model="query.packageId" clearable placeholder="套餐ID" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">产品ID</label>
        <el-input v-model="query.productId" clearable placeholder="产品ID" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">活动矫治器ID</label>
        <el-input v-model="query.applianceId" clearable placeholder="活动矫治器ID" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <label class="el-form-item-label">治疗阶段</label>
        <el-input v-model="query.phase" clearable placeholder="治疗阶段" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"></el-input>
        <date-range-picker
          v-model="query.createDate"
          start-placeholder="createDateStart"
          end-placeholder="createDateStart"
          class="date-item"
        ></date-range-picker>
        <rrOperation :crud="crud"></rrOperation>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission"></crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="病例编号">
            <el-input v-model="form.id" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="患者编号">
            <el-input v-model="form.patientId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="医生编号">
            <el-input v-model="form.doctorId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createDate" type="datetime" style="width: 370px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="记录类型">
            <el-select v-model="form.recordType" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.record_type"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="状态  dict=record_stat">
            <el-select v-model="form.stat" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.record_stat"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="诊所ID">
            <el-input v-model="form.clinicId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="STL标识：0 寄送牙模，1 上传STL文件">
            <el-select v-model="form.stlFlag" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.stl_flag"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="cbct标识：0 上传X光照 ，1 上传CBCT文件 ">
            <el-select v-model="form.cbctFlag" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.cbct_flag"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否需要报告 0 不需要 1 需要">
            <el-select v-model="form.reportFlag" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.report_flag"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="检查信息">
            <el-input v-model="form.examine" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="牙模的快递单号">
            <el-input v-model="form.expressNo" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="套餐ID">
            <el-input v-model="form.packageId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="产品ID">
            <el-input v-model="form.productId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="活动矫治器ID">
            <el-input v-model="form.applianceId" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="是否使用其他治疗方案。0，不使用其他治疗方案；1，使用其他治疗方案">
            <el-input v-model="form.otherPlanFlag" style="width: 370px;"></el-input>
          </el-form-item>
          <el-form-item label="治疗阶段">
            未设置字典，请手动设置 Select
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" stripe :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" sortable label="病例编号"></el-table-column>
        <el-table-column prop="patientId" sortable label="患者编号"></el-table-column>
        <el-table-column prop="doctorId" sortable label="医生编号"></el-table-column>
        <el-table-column prop="createDate" sortable label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="recordType" sortable label="记录类型">
          <template slot-scope="scope">
            {{ dict.label.record_type[scope.row.recordType] }}
          </template>
        </el-table-column>
        <el-table-column prop="stat" sortable label="状态  dict=record_stat">
          <template slot-scope="scope">
            {{ dict.label.record_stat[scope.row.stat] }}
          </template>
        </el-table-column>
        <el-table-column prop="diagnosis" sortable label="医生诉求及设计思路"></el-table-column>
        <el-table-column prop="chiefComplaint" sortable label="患者主诉"></el-table-column>
        <el-table-column prop="clinicId" sortable label="诊所ID"></el-table-column>
        <el-table-column prop="stlFlag" sortable label="STL标识：0 寄送牙模，1 上传STL文件">
          <template slot-scope="scope">
            {{ dict.label.stl_flag[scope.row.stlFlag] }}
          </template>
        </el-table-column>
        <el-table-column prop="cbctFlag" sortable label="cbct标识：0 上传X光照 ，1 上传CBCT文件 ">
          <template slot-scope="scope">
            {{ dict.label.cbct_flag[scope.row.cbctFlag] }}
          </template>
        </el-table-column>
        <el-table-column prop="reportFlag" sortable label="是否需要报告 0 不需要 1 需要">
          <template slot-scope="scope">
            {{ dict.label.report_flag[scope.row.reportFlag] }}
          </template>
        </el-table-column>
        <el-table-column prop="examine" sortable label="检查信息"></el-table-column>
        <el-table-column prop="expressNo" sortable label="牙模的快递单号"></el-table-column>
        <el-table-column prop="reportResult" sortable label="技术中心评估结果代码"></el-table-column>
        <el-table-column prop="packageId" sortable label="套餐ID"></el-table-column>
        <el-table-column prop="productId" sortable label="产品ID"></el-table-column>
        <el-table-column prop="design" sortable label="隐形矫治器设计单"></el-table-column>
        <el-table-column prop="remark" sortable label="医生备注"></el-table-column>
        <el-table-column prop="applianceId" sortable label="活动矫治器ID"></el-table-column>
        <el-table-column prop="otherAppliance" sortable label="其他活动矫治器名称"></el-table-column>
        <el-table-column prop="otherPlanFlag" sortable label="是否使用其他治疗方案。0，不使用其他治疗方案；1，使用其他治疗方案">
          <template slot-scope="scope">
            {{ dict.label.other_plan_flag[scope.row.otherPlanFlag] }}
          </template>
        </el-table-column>
        <el-table-column prop="otherPlanDesc" sortable label="其他治疗方案说明，当other_plan_flag=1时有效"></el-table-column>
        <el-table-column prop="relatedMrId" sortable label="关联病例ID，当病例类型为02普通病例时有效"></el-table-column>
        <el-table-column prop="phase" sortable label="治疗阶段"></el-table-column>
        <el-table-column v-permission="['admin','medicalRecord:edit','medicalRecord:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            ></udOperation>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination></pagination>
    </div>
  </div>
</template>

<script>
import crudMedicalRecord from '@/api/medicalRecord';
import CRUD, { presenter, header, form, crud } from '@crud/crud';
import rrOperation from '@crud/RR.operation';
import crudOperation from '@crud/CRUD.operation';
import udOperation from '@crud/UD.operation';
import pagination from '@crud/Pagination';

const defaultForm = { id: null, patientId: null, doctorId: null, createDate: null, recordType: null, stat: null, diagnosis: null, chiefComplaint: null, clinicId: null, stlFlag: null, cbctFlag: null, reportFlag: null, examine: null, expressNo: null, reportResult: null, packageId: null, productId: null, design: null, remark: null, applianceId: null, otherAppliance: null, otherPlanFlag: null, otherPlanDesc: null, relatedMrId: null, phase: null };
export default {
  name: 'MedicalRecord',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['record_type', 'record_stat', 'stl_flag', 'cbct_flag', 'report_flag', 'other_plan_flag'],
  cruds() {
    return CRUD({ title: 'medicalrecord', url: 'patient/medicalRecord/queryPage', sort: 'id,desc', crudMethod: { ...crudMedicalRecord } });
  },
  data() {
    return {
      permission: {
        add: ['admin', 'medicalRecord:add'],
        edit: ['admin', 'medicalRecord:edit'],
        del: ['admin', 'medicalRecord:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: '病例编号' },
        { key: 'patientId', display_name: '患者编号' },
        { key: 'doctorId', display_name: '医生编号' },
        { key: 'recordType', display_name: '记录类型' },
        { key: 'stat', display_name: '状态  dict=record_stat' },
        { key: 'clinicId', display_name: '诊所ID' },
        { key: 'stlFlag', display_name: 'STL标识：0 寄送牙模，1 上传STL文件' },
        { key: 'cbctFlag', display_name: 'cbct标识：0 上传X光照 ，1 上传CBCT文件 ' },
        { key: 'reportFlag', display_name: '是否需要报告 0 不需要 1 需要' },
        { key: 'expressNo', display_name: '牙模的快递单号' },
        { key: 'packageId', display_name: '套餐ID' },
        { key: 'productId', display_name: '产品ID' },
        { key: 'applianceId', display_name: '活动矫治器ID' },
        { key: 'phase', display_name: '治疗阶段' }
      ]
    };
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    }
  }
};
</script>

<style scoped>

</style>
